package com.china08.yxyapi.api.manage.stu.myclass.stuattendance;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import com.china08.yxyapi.api.YxyApiBaseController;
import com.china08.yxyapi.entity.mg.attendance.YxyStuAttendance;
import com.china08.yxyapi.model.YxyApiReqModel;
import com.china08.yxyapi.model.YxyApiRespModel;
import com.china08.yxyapi.repository.mg.attendance.YxyStuAttendanceRepository;

/**
 * 晨检到班-家长/学生-考勤记录
 * 
 * @author LiuWeidong
 *
 */
@CrossOrigin
@RestController
public class YxyStuAttendanceSrhController extends YxyApiBaseController {

    @Autowired
    private YxyStuAttendanceRepository yxyStuAttendanceRepository;

    @RequestMapping(value = "/api_yw/manage/tec/office/attendance/stu/srh", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public List<RespModel> precess(HttpServletRequest request, HttpServletResponse response,
            @RequestBody ReqModel reqModel) {

        String schoolId = getProfile(request, response).getSchoolId();
        Integer monthDate = reqModel.monthDate;
        List<String> studentId = reqModel.stuIdLst;

        List<RespModel> returnList = new ArrayList<>();
        List<YxyStuAttendance> stuAttendances = yxyStuAttendanceRepository
                .findBySchoolIdAndMonthDateAndStudentIdIn(schoolId, monthDate, studentId);
        for (YxyStuAttendance yxyStuAttendance : stuAttendances) {
            RespModel model = new RespModel();
            model.id = yxyStuAttendance.getId();
            model.dayDate = yxyStuAttendance.getDayDate();
            model.studentName = yxyStuAttendance.getStudentName();
            model.signInDate = yxyStuAttendance.getSignInDate();
            model.signOutDate = yxyStuAttendance.getSignOutDate();
            model.inspection = yxyStuAttendance.getInspection();
            model.inspectionDate = yxyStuAttendance.getInspectionDate();
            model.signClass = yxyStuAttendance.getSignClass();
            model.signClassDate = yxyStuAttendance.getSignClassDate();
            model.studentNo = yxyStuAttendance.getStudentNo() == null ? null : yxyStuAttendance.getStudentNo();
            model.className = yxyStuAttendance.getClassName();
            returnList.add(model);

        }
        return returnList;
    }

    /* 请求参数 */
    protected static class ReqModel extends YxyApiReqModel {

        // 选择月份（例：201705）
        public Integer monthDate;

        // 学生ID（集合）
        public List<String> stuIdLst;
        // public String studentId;
    }

    /* 响应参数 */
    protected static class RespModel extends YxyApiRespModel {
        // id
        public String id;
        // 日期
        public Integer dayDate;
        // 学生姓名
        public String studentName;
        // 到校时间
        public Date signInDate;
        // 离校时间
        public Date signOutDate;
        // 晨检状态
        public String inspection;
        // 晨检时间
        public Date inspectionDate;
        // 到班状态
        public Integer signClass;
        // 到班时间
        public Date signClassDate;
        // 学号
        public Long studentNo;
        // 班级名称
        public String className;
    }
}
